<?php

namespace app\Modules\Api\models;

use app\models\Saleorder as BaseModel;

/**
 * LoginForm is the model behind the login form.
 *
 * @property user|null $user This property is read-only.
 *
 */
class Saleorder extends BaseModel
{
    public function fields()
    {
        $fields = parent::fields();
        $strvalfields = [
            'orderid',
            'user_id',
            'product_id',
            'auction_id',
            'market_val',
            'price',
            'bid_price',
            'num',
            'state',
        ];
        $fields['pimg'] = function(){
            $pic = $this->pimg?$this->pimg:'default_photo.jpg';
            return \Yii::$app->params['uploadUrl'].$pic;
        };
        foreach($strvalfields as $strvalfield){
            $fields[$strvalfield] = function() use ($strvalfield){
                return strval($this->$strvalfield);
            };
        }
        $dateFields = ['created_at','updated_at'];
        foreach($dateFields as $dateField){
            $fields[$dateField] = function() use($dateField){
                return Date('Y-m-d G:i:s',$this->$dateField);
            };
        }
        unset(
            $fields['name'],
            $fields['phone'],
            $fields['qq'],
            $fields['alipay'],
            $fields['aliname'],
            $fields['province'],
            $fields['city'],
            $fields['county'],
            $fields['detail'],
            $fields['pay_type'],
            $fields['trade_no'],
            $fields['buyer_email']
        );
        return $fields;
    }
}